local wendao = fk.CreateSkill{
  name = "pegasus__wendao",
}

local prompts = {}
prompts.give = "#pegasus__wendao-give"

Fk:loadTranslationTable{
  ["pegasus__wendao"] = "问道",
  [":pegasus__wendao"] = "出牌阶段限一次，你可以令一名角色进行【浮雷】判定直至因此受到伤害，然后你令一名角色获得这些判定牌，若不为同一名角色，失去此技能。",
  ["#pegasus__wendao"] = "可以令一名角色进行【浮雷】判定直至因此受到伤害，再令一名角色获得这些判定牌",

  [prompts.give] = "问道：令一名角色获得这些判定牌，若不为同一名角色，失去此技能。",
}

wendao:addEffect("active", {
  anim_type = "offensive",
  prompt = "#pegasus__wendao",
  can_use = function (self, player)
    return player:usedSkillTimes(wendao.name, Player.HistoryPhase) == 0
  end,
  target_num = 1,
  card_num = 0,
  target_filter = function (self, player, to_select, selected)
    return #selected < 1
  end,
  card_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = {}

    while true do
      local judge = {
        who = target,
        reason = "floating_thunder",
        pattern = ".|.|spade",
      }
      room:judge(judge)
      if judge.card then
        table.insertIfNeed(cards, judge.card)
        if judge.card.suit == Card.Spade and not target.dead then
          room:damage{
            to = target,
            damage = 1,
            damageType = fk.ThunderDamage,
            skillName = wendao.name,
          }
          break
        end
      end
    end

    cards = table.filter(cards, function (id)
      return room:getCardArea(id) == Card.DiscardPile
    end)
    if #cards == 0 then return end

    local targetB = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = 1,
      skill_name = wendao.name,
      cancelable = false,
      prompt = prompts.give,
    })[1]

    if targetB ~= target then
      room:handleAddLoseSkills(player, "-" .. wendao.name)
    end

    room:moveCardTo(cards, Card.PlayerHand, targetB, fk.ReasonJustMove, wendao.name, nil, true, player)
  end
})

return wendao